package top.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.Get;
import org.apiguardian.api.API;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import top.api.common.ResponseResult;
import top.api.domain.dto.TagDto;
import top.api.domain.vo.PageVo;
import top.api.service.TagService;

@RestController
@RequestMapping("/content/tag")
@Api(tags = "标签")
@PreAuthorize("@ps.hasPermission('content:tag:index')") // 权限校验
public class TagController {
    @Autowired
    private TagService tagService;

    /**
     * 动态分页查询
     * @param pageNum
     * @param pageSize
     * @param
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "动态分页查询")
    public ResponseResult<PageVo> list(@RequestParam Integer pageNum,@RequestParam Integer pageSize, TagDto tagDto){
        return tagService.pageTagList(pageNum,pageSize,tagDto);
    }

    /**
     * 添加标签
     * @param tagDto
     * @return
     */
    @PostMapping
    @ApiOperation(value = "添加标签")
    public ResponseResult addTag(@RequestBody TagDto tagDto){
        return tagService.addTag(tagDto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除标签")
    public ResponseResult deleteTag(@PathVariable Long id){
        return tagService.deleteTagById(id);
    }

    /**
     * 查询标签
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "查询标签")
    public ResponseResult getTag(@PathVariable Long id){
        return tagService.getTag(id);
    }

    /**
     * 修改标签
     * @param tagDto
     * @return
     */
    @PutMapping
    @ApiOperation(value = "修改标签")
    public ResponseResult updateTag(@RequestBody TagDto tagDto){
        return tagService.updateTag(tagDto);
    }

    /**
     * 查询所有标签
     * @return
     */
    @GetMapping("/listAllTag")
    @ApiOperation(value = "查询所有标签")
    public ResponseResult getListAllTag(){
        return tagService.getListAllTag();
    }

}
